package service

import (
	"context"
	"videosS_rpc/basic/config"
	__ "videosS_rpc/basic/proto"
	"videosS_rpc/handler/model"
)

func (s *Server) BulletAdd(_ context.Context, in *__.BulletAddReq) (*__.BulletAddResp, error) {

	bullet := model.Bullet{
		VideoId:   int(in.VideoId),
		EpisodeId: int(in.EpisodeId),
		PlayTime:  in.PlayTime,
		Content:   in.Content,
		Color:     in.Color,
	}
	err := bullet.BulletAdd(config.DB)
	if err != nil {
		return nil, err
	}
	return &__.BulletAddResp{
		BulletId: int64(bullet.ID),
	}, nil
}

func (s *Server) BulletList(_ context.Context, in *__.BulletListReq) (*__.BulletListResp, error) {

	bullet := model.Bullet{}
	list, err := bullet.BulletList(config.DB)
	if err != nil {
		return nil, err
	}
	return &__.BulletListResp{
		List: list,
	}, nil
}
